package com.baozun.houji.goods.adapter

import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import com.baozhun.mall.common.base.BaseListAdapter
import com.baozun.houji.goods.R
import com.baozun.houji.goods.databinding.SearchAssociativeTagLayoutBinding
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/12
 * @Version：1.0.0
 */
class SearchAssociativeListAdapter(val keywords: String, data: MutableList<String>) : BaseListAdapter<String, SearchAssociativeTagLayoutBinding>(
    R.layout.search_associative_tag_layout, data) {

    override fun convert(holder: BaseDataBindingHolder<SearchAssociativeTagLayoutBinding>, item: String) {
        val content = SpannableString(item)
        val start = content.indexOf(keywords, 0, true)
        val length = keywords.length
        if (start >= 0 && length >= 0) {
            content.setSpan(ForegroundColorSpan(Color.parseColor("#000000")), start, start + length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        }

        holder.dataBinding?.searchAssociativeTv?.text = content
        holder.itemView.setTag(com.baozhun.mall.common.R.id.tag_flag_associative, true)
        holder.dataBinding?.executePendingBindings()
    }
}